package org.wtj.service.sys;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wtj.entity.ResponsePageEntity;
import org.wtj.entity.sys.SysUserConditionEntity;
import org.wtj.entity.sys.SysUserEntity;
import org.wtj.mapper.BaseMapper;
import org.wtj.mapper.sys.SysUserMapper;
import org.wtj.service.BaseService;

import java.util.List;

/**
 * 用户 服务层
 *
 * @author wang 该项目是知识星球：java突击队 的内部项目
 * @date 2025-03-06 21:50:53
 */
@Service
public class SysUserService extends BaseService<SysUserEntity, SysUserConditionEntity> {

	@Autowired
	private SysUserMapper sysUserMapper;

	/**
     * 查询用户信息
     *
     * @param id 用户ID
     * @return 用户信息
     */
	public SysUserEntity findById(Long id) {
	    return sysUserMapper.findById(id);
	}

	/**
     * 根据条件分页查询用户列表
     *
     * @param sysUserConditionEntity 用户信息
     * @return 用户集合
     */
	public ResponsePageEntity<SysUserEntity> searchByPage(SysUserConditionEntity sysUserConditionEntity) {
		int count = sysUserMapper.searchCount(sysUserConditionEntity);
		if (count == 0) {
			return ResponsePageEntity.buildEmpty(sysUserConditionEntity);
		}
		List<SysUserEntity> dataList = sysUserMapper.searchByCondition(sysUserConditionEntity);
		return ResponsePageEntity.build(sysUserConditionEntity, count, dataList);
	}

    /**
     * 新增用户
     *
     * @param sysUserEntity 用户信息
     * @return 结果
     */
	public int insert(SysUserEntity sysUserEntity) {
	    return sysUserMapper.insert(sysUserEntity);
	}

	/**
     * 修改用户
     *
     * @param sysUserEntity 用户信息
     * @return 结果
     */
	public int update(SysUserEntity sysUserEntity) {
	    return sysUserMapper.update(sysUserEntity);
	}

	/**
     * 批量删除用户对象
     *
     * @param ids 系统ID集合
     * @return 结果
     */
	public int deleteByIds(List<Long> ids) {
		List<SysUserEntity> entities = sysUserMapper.findByIds(ids);

		SysUserEntity entity = new SysUserEntity();
		return sysUserMapper.deleteByIds(ids, entity);
	}

	@Override
	protected BaseMapper getBaseMapper() {
		return sysUserMapper;
	}

}
